﻿using FinModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FinPnl
{
    public class PnlCalculator : IPnlCalculate
    {
        public Pnl[] Calculate(IEnumerable<Trade> trades)
        {
            List<Pnl> pnls = new List<Pnl>();

            foreach (var ts in trades.Select(p => p.TS).Distinct())
            {
                pnls.Add(new Pnl()
                {
                    TS = ts,
                    Value = trades.Where(p => p.TS <= ts).Sum(p => p.Quantity * p.Price)
                });
            }

            return pnls.ToArray();
        }
    }
}
